<?php
require_once("./common.php");

$index = 0;

$poll_id = $_GET['poll_id'];

foreach ($_POST['choice'] as $choice){
  $value = 1<<$index++;
  $choice = urlencode($choice);
  $query = "INSERT INTO poll_options VALUES ('$poll_id', '$choice', '$value');";
  mysql_query($query);  
}

$maxselect = $_POST['maxselect'];
if (is_numeric($maxselect) && $maxselect != false) {
  $query = "UPDATE polls SET maxselect='$maxselect' where id='$poll_id';";
  mysql_query($query);
}

header("Location: poll.php?poll_id=" .  $poll_id);

?>
